package com.example.javapoint.threads.pool;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Tasks implements Runnable{
    private String taskName;

    public Tasks(String taskName) {
        this.taskName = taskName;
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
            if (i == 0) {
                System.out.println("初始化线程任务的信息: " + taskName + "=" + sdf.format(date));
            }else {
                System.out.println("执行线程任务的信息: " + taskName + "=" + sdf.format(date));
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println(taskName + "线程任务执行完成");
        }
    }
}
